package com.qty.apkviewer.log

const val TAG = "ApkViewer"
const val DEBUG = true
const val WARN = true
const val ERROR = true
const val INFO = true
object QLog {

    fun d(any: Any?, msg: String): Int {
        return if (DEBUG) {
            android.util.Log.d(TAG, "${getPrefix(any)} $msg")
        } else {
            -1
        }
    }

    fun d(any: Any?, msg: String, tr: Throwable): Int {
        return if (DEBUG) {
            android.util.Log.d(TAG, "${getPrefix(any)} $msg", tr)
        } else {
            -1
        }
    }

    fun e(any: Any?, msg: String): Int {
        return if (ERROR) {
            android.util.Log.e(TAG, "${getPrefix(any)} $msg")
        } else {
            -1
        }
    }

    fun e(any: Any?, msg: String, tr: Throwable): Int {
        return if (ERROR) {
            android.util.Log.e(TAG, "${getPrefix(any)} $msg", tr)
        } else {
            -1
        }
    }

    fun w(any: Any?, msg: String): Int {
        return if (WARN) {
            android.util.Log.w(TAG, "${getPrefix(any)} $msg")
        } else {
            -1
        }
    }

    fun w(any: Any?, msg: String, tr: Throwable): Int {
        return if (WARN) {
            android.util.Log.w(TAG, "${getPrefix(any)} $msg", tr)
        } else {
            -1
        }
    }

    fun i(any: Any?, msg: String): Int {
        return if (WARN) {
            android.util.Log.i(TAG, "${getPrefix(any)} $msg")
        } else {
            -1
        }
    }

    fun i(any: Any?, msg: String, tr: Throwable): Int {
        return if (WARN) {
            android.util.Log.i(TAG, "${getPrefix(any)} $msg", tr)
        } else {
            -1
        }
    }

    private fun getPrefix(any: Any?): String {
        return if (any == null) {
            ""
        } else {
            if (any is String) {
                "[${any}]"
            } else {
                "[${any.javaClass.simpleName}]"
            }
        }
    }
}